/* guess.c -- 一个拖沓且错误的猜数字程序 */
#include <stdio.h>
int main(void)
{
    int guess = 1;

    printf("Pick an integer from 1 to 100. I will try to guess ");
    printf("it.\nRespond with a y if my guess is right and with");
    printf("\nan n if it is wrong.\n");
    printf("Uh...is your number %d?\n", guess);
    while (getchar() != 'y') /* 获取响应，与 y 做对比 */
    {
        // 因为输入非y字符或多个字符时，会获取y和回车两个字符，所以while循环时执行两次，需要清理输入的"\n"字符
        printf("Well, then, is it %d?\n", ++guess);
        while (getchar() != '\n') // 直接跳过回车其它的输入行
        {
            continue;
        }
    }
    printf("I knew I could do it!\n");

    return 0;
}